package weaver.interfaces.jjy.duss.hr;

import com.sap.mw.jco.JCO;
import weaver.interfaces.jjy.duss.util.SAPConnPool;

/*
 *sap数据字典，入参：
 *          IV_TABNAME      PA0000          字典表
 *          IV_FIELDNAME    MASSG           对应字段
 *          IV_SEL	        MASSN = 'Z3'    筛选条件
 * 返回表ET_OUT
 *          VALUE       编号
 *          TEXT        名称
 * */

public class HR000 {

    public String execute(String IV_TABNAME, String IV_FIELDNAME, String value) {

        if(value==null){
            return "";
        }

        SAPConnPool SAPConn = new SAPConnPool();
        JCO.Client myConnection = SAPConn.getConnection();
        JCO.Function bapi = SAPConn.excuteBapi("ZFM_GET_TEXT_TABLE");

        JCO.ParameterList input = bapi.getImportParameterList();//输入参数和结构处理
        //JCO.ParameterList inputtable= bapi.getTableParameterList();//输入表的处理

        //入参为字段
        input.setValue(IV_TABNAME, "IV_TABNAME");
        input.setValue(IV_FIELDNAME, "IV_FIELDNAME");
        //input.setValue("PA0001","IV_TABNAME");
        //input.setValue("WERKS","IV_FIELDNAME");
        //input.setValue("MASSG = 'Z3'","IV_SEL");

        //执行函数
        myConnection.execute(bapi);
        JCO.ParameterList out = bapi.getExportParameterList();//输出参数和结构处理
        JCO.ParameterList Table00 = bapi.getTableParameterList();//输出表的处理

        //返回值
        //System.out.println("EV_MESSAGE：" + out.getValue("EV_MESSAGE"));

        //返回表
        JCO.Table t = Table00.getTable("ET_OUT");
        for (int i = 0; i < t.getNumRows(); i++) {
            t.setRow(i);
            String VALUE = (String) t.getValue("VALUE");
            //System.out.println("TEXT:" + t.getValue("TEXT"));
            if (VALUE.equals(value)) {
                System.out.println("TEXT:" + t.getValue("TEXT"));
                return (String) t.getValue("TEXT");
            }
        }

        //返回处理结果以及日志
//      String[] strs={"EV_OUTPUT","PS0000","PS0001","PS9007"};
//      SAPConn.SAPreturnS(strs,out);

//      String[] tabs={"PT0006"};
//      SAPConn.SAPreturnT(tabs,Table00);
        return "";
        //return Action.SUCCESS;
    }

}
